import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/enums/index.dart';
import 'package:geomancy/mock/wealth_data.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/tools/utils.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/common_text.dart';
import 'package:geomancy/widgets/common_title.dart';

class WealthResultDetailPage extends StatefulWidget {
  final CompassSource source;
  final double direction;
  final int index;///具体某个宫位的index
  const WealthResultDetailPage({super.key, required this.source, required this.direction, required this.index});

  @override
  State<WealthResultDetailPage> createState() => _WealthResultDetailPageState();
}

class _WealthResultDetailPageState extends State<WealthResultDetailPage> {
  late String themeTxt;
  late String station;

  @override
  void initState() {
    super.initState();
    themeTxt = widget.source == CompassSource.roomWealth ? '房间' : '工位';
    station = Utils.getCompassStation(widget.direction);
  }
  
  @override
  Widget build(BuildContext context) {
    final List<String> shList = WealthData.gridSLHList[widget.index.toString()]['shList'];
    final List<String> lhList = WealthData.gridSLHList[widget.index.toString()]['lhList'];
    return Scaffold(
      appBar: CommonHeader.appBar(context: context),
      backgroundColor: ColorStyle.pageDefaultColor,
      body: ListView(
        physics: const ClampingScrollPhysics(),
        padding: EdgeInsets.fromLTRB(Constant.PAGEPADDING.w, 20.w, Constant.PAGEPADDING.w, 80.w),
        children: [
          CommonTitleWidget(txt: '$themeTxt财运位'),
          Container(
            margin: EdgeInsets.only(top: 20.w),
            padding: EdgeInsets.fromLTRB(40.w, 30.w, 40.w, 30.w),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: CommonText(txt: WealthData.gridSLHList[widget.index.toString()]['topContent'].toString().replaceAll('房间', themeTxt), height: 1.5),
          ),
          Container(
            margin: EdgeInsets.symmetric(vertical: 40.w),
            child: Image.asset('assets/grid/grid_wealth_compass_${widget.index}.png', width: 670.w),
          ),
          const CommonTitleWidget(txt: '地支三合'),
          Container(
            margin: EdgeInsets.only(top: 20.w),
            padding: EdgeInsets.fromLTRB(40.w, 25.w, 40.w, 25.w),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: (WealthData.gridSLHList[widget.index.toString()]['shContent'] as List).map((item) {
                return Container(
                  padding: EdgeInsets.symmetric(vertical: 5.w),
                  child: CommonText(txt: item.replaceAll('房间', themeTxt), height: 1.5),
                );
              }).toList(),
            ),
          ),
          Column(
            children: shList.map((item) {
              return Container(
                margin: EdgeInsets.only(top: 40.w),
                child: Image.asset('assets/grid/wealth_sanheju_$item.png', width: 670.w),
              );
            }).toList(),
          ),
          SizedBox(height: 80.w),
          const CommonTitleWidget(txt: '地支六合'),
          Container(
            margin: EdgeInsets.only(top: 20.w),
            padding: EdgeInsets.fromLTRB(40.w, 25.w, 40.w, 25.w),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            // child: CommonText(txt: WealthData.gridSLHList[widget.index.toString()]['lhContent'].toString().replaceAll('房间', themeTxt), height: 1.5),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: (WealthData.gridSLHList[widget.index.toString()]['lhContent'] as List).map((item) {
                return Container(
                  padding: EdgeInsets.symmetric(vertical: 5.w),
                  child: CommonText(txt: item.replaceAll('房间', themeTxt), height: 1.5),
                );
              }).toList(),
            ),
          ),
          Column(
            children: lhList.map((item) {
              return Container(
                margin: EdgeInsets.only(top: 40.w),
                child: Image.asset('assets/grid/wealth_liuheju_$item.png', width: 670.w),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }
}
